#include "sdlTextImage.h"

using std::string;
using ColorTextImage::Colors;
using ColorTextImage::blanco;
using ColorTextImage::rojo;
using ColorTextImage::negro;
using ColorTextImage::azul;
using ColorTextImage::verde;
using ColorTextImage::amarillo;
using ColorTextImage::violeta;


void sdlTextImage::decodeColor(Colors color, SDL_Color& textColor){
	switch(color){
		case blanco:
			textColor.r = 255;
			textColor.g = 255;
			textColor.b = 255;
			break;
		case negro:
			textColor.r = 0;
			textColor.g = 0;
			textColor.b = 0;
			break;
		case rojo:
			textColor.r = 128;
			textColor.g = 0;
			textColor.b = 0;
			break;
		case azul:
			textColor.r = 0;
			textColor.g = 0;
			textColor.b = 128;
			break;
		case verde:
			textColor.r = 0;
			textColor.g = 128;
			textColor.b = 0;
			break;
		case amarillo:
			textColor.r = 255;
			textColor.g = 255;
			textColor.b = 0;
			break;
		case violeta:
			textColor.r = 255;
			textColor.g = 0;
			textColor.b = 255;
			break;
		default: 
			textColor.r = 145;
			textColor.g = 91;
			textColor.b = 13;
	};
}

bool sdlTextImage::renderText(sdlFont& font, const string& msj, Colors color){
	//Soporta algunos colores, falta violeta, amarillo y naranja
	SDL_Color textColor;
	this->decodeColor(color,textColor);
	if (this->surface != NULL){
		SDL_FreeSurface(this->surface);
		this->surface = NULL;
	}
	this->surface = TTF_RenderText_Solid(font.getFont(), msj.c_str(), textColor);
	if (this->surface == NULL){return false;}
	return true;
}
